 ///
 /// @file    virtual_inherit.cc
 /// @author  lemon(haohb13@gmail.com)
 /// @date    2016-03-15 15:23:49
 ///
 
#include <iostream>
using std::cout;
using std::endl;


class A 
{
public:
	A(): _ia(10){}
	virtual void f()
	{	cout << "A::f()" << endl;	}
private:
	int _ia;
};

class B : public A //多了一个虚基指针
{
public:
	B(): _ib(20){}
	void fb()
	{	cout << "B::fb()" << endl;	}
private:
	int _ib;
};

int main(void)
{
	B b;
	cout << "sizeof(b) = " << sizeof(b) << endl;	

	typedef void (*Function) (void);

	int **pVtable = (int **)&b;
	int pVtableAddr = *(int*)pVtable;//虚函数表的入口地址
	int pVtableFirstFunctionAddr = *(int*)pVtableAddr;
	Function pfun = (Function)pVtableFirstFunctionAddr;
	pfun();

	return 0;
}
